﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlarmManagePlatform.Forms
{
    internal partial class MainForm : MetroFramework.Forms.MetroForm
    {
        internal event EventHandler Event_FormClosing;
        internal MainForm()
        {
            InitializeComponent();
            this.Text = "现场智能便携式气体检测仪检定系统";
            this.WindowState = FormWindowState.Maximized;
            this.MinimizeBox = true;
            this.FormClosing += MainForm_FormClosing;
            this.Load += MainForm_Load;
            webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted;
            labUserInfo.Text = "用户：管理员    角色：管理员";
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                //这个文件于可执行文件放在同一目录
                webBrowser1.Url = new Uri(Path.Combine(Application.StartupPath, "Resources\\Baidu.html"));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //这里传入x、y的值，调用JavaScript脚本
            webBrowser1.Document.InvokeScript("setLocation", new object[] { 113.542833, 34.809629 });
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Event_FormClosing?.Invoke(sender, e);
        }

        private void btnUserMng_Click(object sender, EventArgs e)
        { 
            UserMng userMng = new UserMng();
            userMng.ShowDialog(this);
        }
    }
}
